package org.xtext.dsl.generator;

import com.google.inject.Inject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xtend2.lib.ResourceExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.xtext.dsl.teste.Greeting;
import org.xtext.dsl.teste.Model;

@SuppressWarnings("all")
public class TesteGenerator implements IGenerator {
  
  @Inject
  private IQualifiedNameProvider nameProvider;
  
  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    Iterable<EObject> _allContentsIterable = ResourceExtensions.allContentsIterable(resource);
    Iterable<Model> _filter = IterableExtensions.<Model>filter(_allContentsIterable, org.xtext.dsl.teste.Model.class);
    for (Model e : _filter) {
      StringConcatenation _hellos = this.hellos(e);
      fsa.generateFile("Hellos.java", _hellos);
    }
  }
  
  public StringConcatenation hellos(final Model m) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("public class Hellos{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static void main (String[] args){");
    _builder.newLine();
    {
      EList<Greeting> _greetings = m.getGreetings();
      for(Greeting g : _greetings) {
        _builder.append("\t\t");
        StringConcatenation _hello = this.hello(g);
        _builder.append(_hello, "		");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation hello(final Greeting g) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("System.out.println(\"Hello ");
    String _name = g.getName();
    _builder.append(_name, "");
    _builder.append("!\");");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
}